﻿using KFC.ThanhVienF;
using KFC.MonAnF;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace KFC.Model
{
    public class HoaDon
    {
        private List<MonAn> danhSachMonAn;
        private List<int> dDanhSachSoLuong; 
        private List<int> GiaLucBan;
        private DateTime NgayLap;
        private int tienTruocGiamGia;
        private int tienSauKhiGiamGia;
        
        private KhachHang khachHang;

        public HoaDon()
        {
            danhSachMonAn = new List<MonAn>();
            dDanhSachSoLuong = new List<int>();
            GiaLucBan = new List<int>();
           
            NgayLap = DateTime.Now;
            tienTruocGiamGia = 0;
            tienSauKhiGiamGia = 0;

        }

        public int TinhTien()
        {
            tienTruocGiamGia = 0;
            for (int i = 0; i<danhSachMonAn.Count; i++)
            {
                tienTruocGiamGia += danhSachMonAn[i].DonGia * dDanhSachSoLuong[i];
            }
            return tienTruocGiamGia;
        }

        public int TinhTienHoaDon(int maThe)
        {
            if (maThe == -1)
            {
                khachHang = new KhachHangThuong();
            }
            else
            {
                khachHang = new ThanhVien(maThe);
            }
            tienSauKhiGiamGia = khachHang.TinhTien(tienTruocGiamGia);
            return tienSauKhiGiamGia;
        }

        public void ThemMonAn(MonAn ma, int SoLuong)
        {
            // neu mon do da dc dat rui
            for (int i = 0; i < danhSachMonAn.Count; i++)
            {
                if (danhSachMonAn[i].MaMonAn == ma.MaMonAn)
                {
                    dDanhSachSoLuong[i] = SoLuong;
                    return;
                }
            }

            danhSachMonAn.Add(ma);
            dDanhSachSoLuong.Add(SoLuong);
        }

        public void Luu()
        {
            // send hoa don len server
        }
        public List<MonAn> DanhSachMonAn
        {
            get { return danhSachMonAn; }
        }
        public List<int> DanhSachSoLuong
        {
            get { return dDanhSachSoLuong; }
        }
       
    }
}
